home *** CD-ROM | disk | FTP | other *** search
GW-BASIC | 1987-03-11 | 2.8 KB | 70 lines |
- 10 ' Romberg Integration Routine
- 20 ' Copyright 1987 - Joseph D. Cusimano, P.O. Box 2622, Norman, OK 73070
- 30 ' All Rights Reserved
- 40 SCREEN 0,0,0:WIDTH 80:KEY OFF:CLS
- 50 ON KEY(1) GOSUB 630:KEY(1) ON
- 60 LOCATE 1,24,0:PRINT "Romberg Integration Routine V2.1"
- 70 PRINT
- 80 PRINT " Directions: =====> INSERT FUNCTION TO INTEGRATE AT LINE NUMBER 610 <===="
- 90 PRINT " ------------------------------------------------------------"
- 100 PRINT " List lines 605 on and follow directions then run the program."
- 110 PRINT " You will be prompted for the limits of integration and "
- 120 PRINT " the convergence criterion. To quit at any time just press"
- 130 PRINT " the F1 function key."
- 140 PRINT
- 150 PRINT " This utility is provided on an as-is basis only. This has been released"
- 160 PRINT " for the publics free use, but it IS copyrighted and not to be used for"
- 170 PRINT " profit by anyone without prior permission! Please leave the copyright "
- 180 PRINT " notice in this source program! (Your conscience will haunt you forever"
- 190 PRINT " and ever if you don't!) If you have any suggestions, comments, or "
- 200 PRINT " questions, send them to:"
- 210 PRINT " Joe Cusimano"
- 220 PRINT " P.O. Box 2622"
- 230 PRINT " Norman, OK 73070"
- 240 PRINT
- 250 PRINT " (C) Copyright 1987, Joseph D. Cusimano"
- 260 PRINT " All Rights Reserved"
- 270 PRINT:PRINT " Press any key to continue"
- 280 FOR X!=1 TO 40:A$=INKEY$:NEXT X!
- 290 A$=INKEY$:IF A$="" THEN 290
- 300 CLS:CLEAR
- 310 ' ====> INSERT FUNCTION TO INTEGRATE INTO LINE 610 <====
- 320 DIM T#(50,50)
- 330 PRINT:INPUT "What is the limit of integration, A ";A#
- 340 PRINT:INPUT "What is the limit of integration, B ";B#
- 350 PRINT:INPUT "What is convergence criterion ";ER#
- 360 PRINT:PRINT "SOLVING - Be patient, depending on your convergence criterion and the function,"
- 365 PRINT " this can take several minutes.":PRINT:PRINT
- 370 X#=A#:GOSUB 610:FA#=FX#:X#=B#:GOSUB 610:FB#=FX#:X#=(A#+B#)/2:GOSUB 610:FAB#=FX#
- 380 T#(1,1)=((B#-A#)/2)*(FA#+FB#)
- 390 T#(1,2)=(T#(1,1)/2)+((B#-A#)/2)*(FAB#)
- 400 T#(2,1)=(1/3)*(4*T#(1,2)-T#(1,1))
- 410 J=3
- 420 DELX#=(B#-A#)/(2^(J-1))
- 430 X#=A#-DELX#
- 440 N=2^(J-2)
- 450 SUM#=0
- 460 I=1
- 470 X#=X#+2*DELX#
- 480 GOSUB 610
- 490 SUM#=SUM#+FX#
- 500 IF I<>N THEN I=I+1:GOTO 470
- 510 T#(1,J)=(T#(1,J-1)/2)+DELX#*SUM#
- 520 L=2
- 530 K=J+1-L
- 540 T#(L,K)=((4^(L-1))*T#(L-1,K+1)-T#(L-1,K))/(4^(L-1)-1)
- 550 IF L<>J THEN L=L+1:GOTO 530
- 560 IF ABS(T#(J,1)-T#(J-1,1))>ER# THEN J=J+1:GOTO 420
- 570 LL=10
- 580 CC=1
- 590 PRINT "Numerical Solution = ";T#(J,1)
- 600 END
- 605 ' Insert Function to integrate in line 610, it MUST be in terms of FX#
- 606 ' equals some function of X#! [The following example is integrating
- 607 ' one over x squared: FX#=(1)/(x#^2)] 608 '
- 608 '
- 610 FX#=((1)/(X#^2))
- 615 '
- 620 RETURN
- 630 PRINT:PRINT "ABORT - RETURNING TO BASIC":END
-